package com.heima.article.controller;

import com.heima.article.dto.*;
import com.heima.article.entity.ApArticle;
import com.heima.article.service.IApArticleService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 文章信息表，存储已发布的文章 前端控制器
 * </p>
 *
 * @author wsj
 * @since 2022-03-11
 */
@RestController
@RequestMapping("/api/v1/article")
@Api(tags = "文章信息表，存储已发布的文章接口")
public class ApArticleController{

    @Autowired
    private IApArticleService apArticleService;

    /**
     * 保存app端文章
     * @param dto
     * @return
     */
    @ApiOperation(value = "保存app端文章",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "文章参数",required = true,dataType = "ArticleDto")
    @PostMapping
    public ResponseResult<Long> saveArticle(@RequestBody ArticleDto dto) {
        return apArticleService.saveArticle(dto);
    }

    /**
     * app端home界面文章列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    @ApiOperation(value = "app端home界面文章列表",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询参数",required = true,dataType = "ArticleHomeDto")
    public ResponseResult loadArticle(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto,1);
    }
    @PostMapping("/loadmore")
    @ApiOperation(value = "上拉文章列表",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询参数",required = true,dataType = "ArticleHomeDto")
    public ResponseResult loadArticleMore(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto,2);
    }
    @PostMapping("/loadnew")
    @ApiOperation(value = "下拉文章列表",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询参数",required = true,dataType = "ArticleHomeDto")
    public ResponseResult loadArticleNew(@RequestBody ArticleHomeDto dto) {
        return apArticleService.loadArticle(dto,3);
    }

    /**
     * 文章内容
     * @param dto
     * @return
     */
    @PostMapping("/load_article_info")
    @ApiOperation(value = "查看文章内容",notes = "author:wsj")
    @ApiImplicitParam(name = "dto",value = "查询参数",required = true,dataType = "ArticleInfoDto")
    public ResponseResult loadArticleInfo(@RequestBody ArticleInfoDto dto) {
        return apArticleService.loadArticleInfo(dto);
    }

    /**
     * 文章详情
     * @param dto
     * @return
     */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleBehaviorDto dto) {
        return apArticleService.loadArticleBehavior(dto);
    }

    /**
     * 查看文章列表
     * @param dto
     * @return
     */
    @PostMapping("/load_article_comments")
    public ResponseResult loadArticleComments(@RequestBody ArticleCommentDto dto) {
        return apArticleService.loadArticleComments(dto);
    }

    /**
     * 打开或关闭评论
     * @param dto
     * @return
     */
    @PostMapping("/update_comment_status")
    public ResponseResult updateCommentStatus(@RequestBody ArticleCommentStatusDto dto) {
        return apArticleService.updateCommentStatus(dto);
    }

    /**
     * 图文统计
     * @param beginDate
     * @param endDate
     * @return
     */
    @GetMapping("/newsDimension")
    public ResponseResult newsDimension(String beginDate, String endDate) {
        return apArticleService.newsDimension(beginDate,endDate);
    }

    /**
     * 图文列表
     * @param beginDate
     * @param endDate
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getNewsPageStatistics")
    public ResponseResult getNewsPageStatistics(String beginDate, String endDate, Integer page, Integer size) {
        return apArticleService.getNewsPageStatistics(beginDate, endDate, page, size);
    }

    /**
     * 获取文章是否能评论
     * @param id
     * @return
     */
    @PutMapping("/id")
    public ResponseResult<ApArticle> getOperation(@RequestBody Long id){
        ApArticle apArticle = apArticleService.getById(id);
        return ResponseResult.okResult(apArticle);
    }
}
